import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

//静态路由配置
void main() => runApp(const MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  const MyApp3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => const Exam220HomePage(),
      },
    );
  }
}

///代码路径 lib/code2/code219_Button.dart
class Exam220HomePage extends StatefulWidget {
  const Exam220HomePage({Key? key}) : super(key: key);

  @override
  State<Exam220HomePage> createState() => _Exam220HomePageState();
}

class _Exam220HomePageState extends State<Exam220HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //页面的头部
      appBar: AppBar(title: const Text("标题")),
      //页面的主内容区
      body: Container(
        width: double.infinity,
        //竖直方向排开子Widget
        child: Column(
          children: [
            const SizedBox(
              height: 44,
            ),
            buildImage()
          ],
        ),
      ),
    );
  }

  ///代码清单2-24
  ///代码路径 lib/code2/code221_Image.dart
  String imageUrl =
      "https://img-blog.csdnimg.cn/20211031094959816.gif";
  Widget buildImage() {
    return Image.network(
      imageUrl,
      //图片的填充模式
      fit: BoxFit.fill,
      //图片的宽高
      width: 100,
      height: 100,
      //加载中的占位
      loadingBuilder: (
          BuildContext context,
          Widget child,
          loadingProgress,
          ) {
        return const Text("加载中");
      },
      //加载出错
      errorBuilder: (
          BuildContext context,
          Object error,
          stackTrace,
          ) {
        return const Text("加载出错");
      },
    );
  }

  Widget buildImage2() {
    return Image(
      fit: BoxFit.fill,
      width: 100,
      height: 100,
      image: NetworkImage(imageUrl),
    );
  }
  Widget buildImage3() {
    return Image.asset(
      "assets/images/banner_mang.png",
    );
  }

  //或者是
  Widget buildImage4() {
    return const Image(
      image: AssetImage(
        "assets/images/banner_mang.png",
      ),
    );
  }


}
